package com.kunlun.basedata.controller;

import com.kunlun.basedata.model.SystemLinkModel;
import com.kunlun.basedata.service.ISystemLinkService;
import com.kunlun.common.utils.ResponseUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/systemLink")
public class SystemLinkController {

    private Logger log = LogManager.getLogger();

    @Autowired
    private ISystemLinkService systemLinkService;

    @RequestMapping(value = "/getAllLinks", method = RequestMethod.GET)
    public Object getAllLinks(String dataType, String linkName) {
        try {
            Map map = systemLinkService.getAllLinks(dataType, linkName);
            return ResponseUtil.successResponse(map);
        } catch (Exception e) {
            log.error("RoleController getAllLinks Error: ", e);
            return ResponseUtil.failedResponse("查询所有外链失败！", e.getMessage());
        }
    }

    @RequestMapping(value = "/onAddLink", method = RequestMethod.GET)
    public Object onAddLink(SystemLinkModel linkModel) {
        try {
            systemLinkService.onAddLink(linkModel);
            return ResponseUtil.successResponse("新增成功");
        } catch (Exception e) {
            log.error("RoleController getAllLinks Error: ", e);
            return ResponseUtil.failedResponse("新增失败！", e.getMessage());
        }
    }

    @RequestMapping(value = "/onDelete", method = RequestMethod.GET)
    public Object onDelete(String id) {
        try {
            systemLinkService.onDelete(id);
            return ResponseUtil.successResponse("删除成功");
        } catch (Exception e) {
            log.error("RoleController getAllLinks Error: ", e);
            return ResponseUtil.failedResponse("删除失败！", e.getMessage());
        }
    }
}
